// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
  // API 调用都保持和云函数当前所在环境一致
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
const db = cloud.database()
const _ = db.command
const userid=getApp().globalData.userid
var year = new Date().getFullYear() // 示例
var month = new Date().getMonth() + 1
var day = new Date().getDate()
var hours = new Date().getHours()
var minutes = new Date().getMinutes()
var seconds = new Date().getSeconds()
var postid = app.globalData.postid
var time = year + '.' + month + '.' + day + ' ' + hours + ':' + minutes + ':' + seconds
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    try {
        await db.collection('user')
        .where({
            _id:userid
        })
        .update({
            data:{
                guanzhu: _.push({postid:postid,time:time})
            }
        })
    } catch (error) {
        console.error(error)
    }
    return {
        data:event
    }
}
